from rest_framework.views import exception_handler as drf_exception_handlerfrom rest_framework import statusfrom django.db import DatabaseErrorfrom rest_framework.response import Responsedef exception_handler(exc, context):    """自定义异常捕获"""    response = drf_exception_handler(exc, context)  # 先用DRF异常捕获函数去捕获,如果捕获到就会返回一个对应的响应对象(响应对象也指定好了状态码)    if response is None:        view = context['view']        if isinstance(exc, DatabaseError):  # 判断当前的异常实例对象是不是由DatabaseError或它的子类创建出来的,如果是的就说明当前异常是数据库异常            print('[%s]: %s' % (view, exc))            response = Response({'detail': '服务器内部错误'}, status=status.HTTP_507_INSUFFICIENT_STORAGE)    return response